﻿Imports OMANE.Common
Imports OMANE.Common.UI

''' <summary>
''' Class du module  PMT. 
''' </summary>
''' <remarks>C'est le point d'entrée</remarks>
Public Class PMTModule
    Implements IModule

    Private Shared _uiservice As IUIService
    Private Shared _undoredoservice As IUndoRedoService
    Shared _application As Common.Application
    Private Shared _RootNode As V2ViewModelTabGroup
    Private Shared _Model As IModel

    Private ReadOnly Property Dependencies As IEnumerable(Of Common.ModuleReference) Implements Common.IModule.Dependencies
        Get
            Throw New NotImplementedException()
        End Get
    End Property

    Private Sub Load() Implements Common.IModule.Load
    End Sub

    Private Sub Reset(ByVal Application As Common.Application) Implements Common.IModule.Reset
        _application = Application

        _uiservice = Application.GetService(Of IUIService)()

        Dim dic = New Windows.ResourceDictionary()
        dic.Source = New Uri("/OMANE.Modules.PMT;component/Ressources/Ressources.xaml", System.UriKind.Relative)
        UIService.AddResourceDictionary(dic)

        Dim uihelper = New UIHelper(UIService)

        Dim uiconfig = XElement.Load( _
            IO.Path.Combine(IO.Path.GetDirectoryName(Reflection.Assembly.GetAssembly(Me.GetType()).Location), "UIConfig.xml"))

        uihelper.CreateMainMenuFromXml(uiconfig)
        'uihelper.CreateNavigationTreeFromXml(uiconfig)

        _RootNode = New V2ViewModelTabGroup() With {.Title = "Prevision moyen terme"}

        UIService.V2ViewModelAccordeonMenu.Inventaires.Body.Add(RootNode)

        'Les PMT sont deserializés
        Model.deserialize()

        'Ajouter les PMT deserializes dans l'arborescence
        For Each PMT_EnCours In Model.ListePMT

            Dim VMPMT As New ViewModelPMT(PMT_EnCours) With { _
                .Title = "PMT-" & PMT_EnCours.ParametresGeneraux.Mois & PMT_EnCours.ParametresGeneraux.ComplementNom}

            PMTModule.RootNode.Children.Add(New OMANE.Common.UI.V2ViewModelTabGroup With { _
                .Title = "PMT-" & PMT_EnCours.ParametresGeneraux.Mois & PMT_EnCours.ParametresGeneraux.ComplementNom, _
                .TabSection = VMPMT, .TabGroup = PMTModule.RootNode.TabGroup})

            PMTModule.RootNode.TabGroup.Add(VMPMT)
            'PMTModule.Model.ListePMT.Add(NewPMT)

        Next
    End Sub

    Public Shared ReadOnly Property RootNode As V2ViewModelTabGroup
        Get
            Return _RootNode
        End Get
    End Property

    Private Sub Unload() Implements Common.IModule.Unload
        Model.Serialize()
    End Sub

    Public Shared ReadOnly Property Model As IModel
        Get
            If _Model Is Nothing Then
                _Model = New Model
            End If
            Return _Model
        End Get
    End Property

    ''' <summary>
    ''' Service IUIService
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property UIService As IUIService
        Get
            Return _uiservice
        End Get
    End Property

    ''' <summary>
    ''' Service IUndoRedoService
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property UndoRedoService As IUndoRedoService
        Get
            Return _undoredoservice
        End Get
    End Property

    ''' <summary>
    ''' Application
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property Application As Common.Application
        Get
            Return _application
        End Get
    End Property

End Class

